<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Cache;
use App\Models\Category;
use App\Models\Index;
class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    
    public $category = [];
    public function __cate_init__($request)
    {
        //获取当前栏目
        
        $key = 'Category_'.$request->catid;
//         $this->category = Cache::get($key);
        if(!$this->category)
        {
            $this->category = Category::findOrFail($request->catid);
            Cache::put($key, $this->category, 604800);
        }
    }
    
    public function isLastRedirect()
    {
        $category = $this->category;
        //判断是否是跟栏目
        if($category->parent_id == 0 && $category->is_show == 1) {
            $menu = Index::menu();
            return redirect('/'.$menu[$category->id]['child'][0]['controller'].'?catid='.$menu[$category->id]['child'][0]['id']);
        }
        return false;
    }
}
